#coding=utf-8
from django.db import models
from BaiduMap_JS.models import SelectPositionField
from DjangoBbs.Travel.TravelData.models import LineType, City, PositionType
from DjangoUeditor.models import UEditorField
from PublicTool.BaseModel import Base_UserModel


__author__ = 'czq'




class RideLine(Base_UserModel):
    #1为正式发布，2为草稿箱
        # 文章发布状态
    CONTENT_STATUS_PUBLISHED = 1
    # 文章草稿箱状态
    CONTENT_STATUS_DRAFT = 2
    #私密
    CONTENT_STATUS_PRIVATE = 3
    # 文章状态选项
    CONTENT_STATUS_CHOICES = (
        (CONTENT_STATUS_PUBLISHED, '发布'),
        (CONTENT_STATUS_DRAFT, '草稿箱'),
        (CONTENT_STATUS_PRIVATE, '私密日志'),
    )


    LINE_TYPE_GO=0
    LINE_TYPE_GO=1
    LINE_TYPE_SELECT=(
        (LINE_TYPE_GO, '去往'),
        (LINE_TYPE_GO, '回程'),
    )

    name = models.CharField(u"标题",max_length=100)
    content=UEditorField(u'内容',height=200,width=600,imagePath="RideLine",imageManagerPath="RideLine",filePath="RideLine",blank=True,null=True)

    lineType=models.ForeignKey(LineType,verbose_name=u"线路类型")
    startPosition=models.IntegerField(u"起点",null=True,blank=True)
    startTime=models.DateTimeField(u"出发时间",null=True,blank=True)
    endPosition=models.IntegerField(u"终点",null=True,blank=True)
    endTime=models.DateTimeField(u"到达时间",null=True,blank=True)

    status = models.IntegerField('状态',
                                 choices=CONTENT_STATUS_CHOICES,
                                 default=CONTENT_STATUS_PUBLISHED)

    #view_count = models.IntegerField(default=0, editable=False)         # 浏览总数
    #categories=models.ForeignKey(Category,verbose_name=u"分类")

    #visitPerm=models.ForeignKey(VisitPerm,verbose_name=u"访问权限",blank=True,null=True)

    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '骑行线路'
        verbose_name_plural = '骑行线路'
        ordering = ['-addTime']

class Position(Base_UserModel):
    longitude=models.FloatField(u"经度")
    latitude=models.FloatField(u"纬度")
    city=models.ForeignKey(City,verbose_name=u"城市",null=True,blank=True)
    address=SelectPositionField(verbose_name=u"位置",max_length=100,null=True,blank=True,dialog_height='450px',dialog_width ='400px')
    class Meta:
        verbose_name = '位置'
        verbose_name_plural = '位置'

class RidePosition(Position):


    travelLine=models.ForeignKey(RideLine,verbose_name=u"线路",null=True,blank=True)
    content=content=UEditorField(u'内容',height=200,width=600,imagePath="RidePosition",imageManagerPath="RidePosition",filePath="RidePosition",blank=True,null=True)
    arriveTime=models.DateTimeField(u"到达时间",null=True,blank=True,help_text=u'到达这个位置的时间')
    departureTime=models.DateTimeField(u"出发时间",null=True,blank=True,help_text=u'开始去下一个位置的时间')
    #lastPosition=models.ForeignKey('self',verbose_name=u"上一个位置",null=True,blank=True)

    positionType=models.ForeignKey(PositionType,verbose_name=u"位置类型")
    rank=models.IntegerField(u"排序",default=1)
    #positionType=models.IntegerField(u"路段",choices=POS_TYPE_SELECT,default=POS_TYPE_MIDDLE)
    #lastPosition=models.ForeignKey('self',verbose_name=u"上一个地点",related_name='lastPosition',null=True,blank=True)
    #nextPosition=models.ForeignKey('self',verbose_name=u"下一个地点",related_name='nextPosition',null=True,blank=True)
    def __unicode__(self):
        return self.address
    class Meta:
        verbose_name = '骑行位置'
        verbose_name_plural = '骑行位置'
